<?php
/**
 * @file americantwolevelnavcontroller.php
 * @author LinLin
 * @date 2016年4月8日 下午7:11:35
 * @brief 
 */
namespace haibao\cms\business\control\pc\channel\american;

use haibao\cms\business\control\PublicController as PublicControllerBusiness;
class AmericanTwoLevelNavController extends \haibao\cms\business\control\AmericanController{

    public function __construct($updateTime = null,$controlId,$isPublish){
        parent::__construct($updateTime,$controlId,$isPublish);
    }

    /**
     * 显示模版内容（模版动态数据的绑定和模版输出）
     * @param : String $content
     * @param : Array $controlData;
     */
    public function displayTemplateHtml(){
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $path = $this->generateHtmlPath(__CLASS__);
        $autoData = array();
        if($controlData['auto']){
            foreach($controlData['auto'] as $key=>$val){
                $resultData =json_decode($val['ParameterValue']);
                if(isset($resultData->showOrder)){
                    $autoData[$resultData->showOrder] = array('ChannelName'=>$resultData->ChannelName,'ChannelUrl'=>$resultData->ChannelUrl);
                }else{
                    array_push($autoData,array('ChannelName'=>$resultData->ChannelName,'ChannelUrl'=>$resultData->ChannelUrl));
                }
            }
        }
        $channelList = array();
        $countList = 0;
        if(isset($controlData['manual']['site'])){
            $channelList = PublicControllerBusiness::getLowerChannelByParentName($controlData['manual']['site']);
        }
        if($channelList){
            $temp['ChannelName'] = '首页';
            $temp['ChannelUrl'] = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_TV_HOST);
            array_unshift($channelList,$temp);
        }
        if($channelList){
            foreach($autoData as $key=>$list){
                $tmpArr = array(0=>$list);
                array_splice($channelList,$key-1,0,$tmpArr);
            }
            $countList = count($channelList)-1;
        }else{
            $channelList = $autoData;
            $countList = count($channelList);
        }
        $this->assign('channelList', $channelList);
        $this->assign('count',$countList);
        $isNewHtml = $this->generateHtml($path,$content);
        $content = $this->getHtml($path);
        return $content;
    }
} 